// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
#include "pch.h"
#include "ImageTile.h"

using namespace Weathr;

using namespace std;
using namespace Platform;
using namespace Windows::UI::Notifications;
using namespace Windows::Data::Xml::Dom;

TileNotification^ ImageTile::GetTileNotification()
{
    XmlDocument^ content = TileUpdateManager::GetTemplateContent(TileTemplateType::TileSquare310x310Image);
    UpdateContentWithValues(content);
    return ref new TileNotification(content);
}

void ImageTile::SetImageFilePaths(const wstring& hugeTileFileName, const wstring& wideTileFileName, const wstring& squareTileFileName)
{
    m_hugeTileFileName = hugeTileFileName;
    m_wideTileFileName = wideTileFileName;
    m_squareTileFileName = squareTileFileName;
}

void ImageTile::UpdateContentWithValues(XmlDocument^ content)
{
    IXmlNode^ tileImage = content->GetElementsByTagName("image")->GetAt(0);
    tileImage->Attributes->GetNamedItem("src")->InnerText = ref new String(m_hugeTileFileName.c_str());

    XmlDocument^ wideTileXml = TileUpdateManager::GetTemplateContent(TileTemplateType::TileWide310x150Image);
    tileImage = wideTileXml->GetElementsByTagName("image")->First()->Current;
    tileImage->Attributes->GetNamedItem("src")->InnerText = ref new String(m_wideTileFileName.c_str());
    auto node = content->ImportNode(wideTileXml->GetElementsByTagName("binding")->First()->Current, true);
    content->GetElementsByTagName("visual")->First()->Current->AppendChild(node);

    XmlDocument^ squareTileXml = TileUpdateManager::GetTemplateContent(TileTemplateType::TileSquare150x150Image);
    tileImage = squareTileXml->GetElementsByTagName("image")->First()->Current;
    tileImage->Attributes->GetNamedItem("src")->InnerText = ref new String(m_squareTileFileName.c_str());
    node = content->ImportNode(squareTileXml->GetElementsByTagName("binding")->First()->Current, true);
    content->GetElementsByTagName("visual")->First()->Current->AppendChild(node);
}